package com.shop.controller;

import com.jfinal.core.Controller;
import com.shop.model.Blog;
import com.shop.service.BlogService;

/**
 * Blog 管理	
 * 描述：
 * 
 */
public class BlogController extends Controller {

	//private static final Log log = Log.getLog(BlogController.class);
	
	static BlogService srv = BlogService.me;
	
	/**
	 * 列表
	 */
	public void list() {
		setAttr("page", srv.paginate(getParaToInt("p", 1), 40));
		render("blogList.html");
	}
	
	/**
	 * 准备添加
	 * //blog/add
	 */
	public void add() {
		render("blogAdd.html");
	}
	
	/**
	 * 保存
	 */
	public void save() {
		srv.save(getModel(Blog.class));
		renderJson("isOk", true);
	}

	/**
	 * 准备更新
	 */
	public void edit() {
		Blog blog = srv.findById(getParaToInt("id"));
		setAttr("blog", blog);
		render("blogEdit.html");
	}

	/**
	 * 更新
	 */
	public void update() {
		srv.update(getModel(Blog.class));
		renderJson("isOk", true);
	}

	/**
	 * 查看
	 */
	public void view() {
		Blog blog = srv.findById(getParaToInt("id"));
		setAttr("blog", blog);
		render("blogView.html");
	}
	 
	/**
	 * 删除
	 */
	public void delete() {
		srv.delete(getParaToInt("id"));
		renderJson("isOk", true);
	}
	
}